﻿<Window x:Class="XPathAutoSuggest.Views.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:my="clr-namespace:XPathAutoSuggest"
    Title="XPath AutoSuggest and Evaluate" Height="600" Width="720" 
    MinHeight="400" MinWidth="400"
    WindowStartupLocation="CenterScreen"  Loaded="Window_Loaded" 
        Icon="/XPathAutoSuggest;component/Images/XPath40TruncMOre.jpg">
    <DockPanel Background="Black">
        <StatusBar DockPanel.Dock="Bottom">
            <TextBlock Name="txtStatusInfo" Text="{Binding StatusInfo}" />
        </StatusBar>
        <Grid FocusManager.FocusedElement="{Binding ElementName=txtXml}" >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" MinHeight="57" />  <!-- 0-->
                <RowDefinition Height="Auto" MinHeight="24" />
                <RowDefinition Height="3*" />
                <RowDefinition Height="12"/>                    <!-- 3 -->
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" MinHeight="26" />
                <RowDefinition Height="Auto" MinHeight="26" />  <!-- 6 -->
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" MinWidth="78" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" MinWidth="49" />
            </Grid.ColumnDefinitions>

            <Border Style="{StaticResource header}" Grid.ColumnSpan="3" Grid.Row="0">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" >
                    <Image HorizontalAlignment="Right" Margin="3 1 45 1" VerticalAlignment="Top" Source="/XPathAutoSuggest;component/Images/XPath40TruncMOre.jpg" />
                    <TextBlock  Text="XPath Auto-Suggest and Evaluate" HorizontalAlignment="Center" />
                </StackPanel>
            </Border>

            <my:XPathMenu Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Left" />

            <Label Grid.Row="2" Target="{Binding ElementName=txtXml}" Content="_Sample XML:" Foreground="White" />
            <TextBox Grid.Column="1" Name="txtXml" TextWrapping="Wrap" AcceptsTab="True" 
                     AcceptsReturn="True"
                     Grid.Row="2" 
                     Text="{Binding FormattedXml,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" 
                     Background="Honeydew" 
                     HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" 
                     SelectionChanged="txtXml_SelectionChanged" Margin="0,1,0,33" Grid.RowSpan="2"
                     Style="{DynamicResource TextBox_Theme}" Foreground="White" />

            <Grid Grid.Column="2" Grid.Row="2" VerticalAlignment="Top">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Button Content="Suggest" Command="{Binding SuggestCommand}"  Margin="3"
                        Height="24" ToolTip="Frist, highlight a tag or node, then click to generate an XPath query" 
                        Style="{DynamicResource Button_Theme}" 
                        Background="{StaticResource niceGradient}" />
             
                <Button Grid.Row="1" Content="Validate" Background="{StaticResource niceGradient}"
                        Style="{DynamicResource Button_Theme}"
                        Margin="3"
                        Height="24"
                        Command="{Binding ValidateXmlCommand}"
                        />
            </Grid>


            <GridSplitter Grid.Row="3" Height="10" Grid.ColumnSpan="3"
                          HorizontalAlignment="Stretch" 
                          ToolTip="Resize bar"
                          ResizeDirection="Rows" Width="Auto" >
                <GridSplitter.Background>
                    <ImageBrush TileMode="Tile" ImageSource="/XPathAutoSuggest;component/Images/10x1px.jpg" />
                </GridSplitter.Background>
            </GridSplitter>


            <Label Grid.Row="4" Target="{Binding ElementName=grdSuggestions}" Content="X_Path:" Foreground="White" />
            <ScrollViewer Name="grdSuggestions" 
                          Grid.Column="1" Grid.Row="3" Margin="0,12,0,2" Grid.RowSpan="2">
                <ListView ItemsSource="{Binding QuerySuggestions, NotifyOnSourceUpdated=True,
                                        NotifyOnTargetUpdated=True,
                                        UpdateSourceTrigger=PropertyChanged}" 
                          MinHeight="50">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="Suggested Query" DisplayMemberBinding="{Binding Query}" Width="250" />
                            <GridViewColumn Header="Description" DisplayMemberBinding="{Binding Description}"
                                            Width="160" />
                            <GridViewColumn Header="Try It">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button Content="E_valuate" 
                                                MinWidth="80" 
                                                Command="{Binding Path=DataContext.EvaluateCommand, 
                                                    RelativeSource={RelativeSource FindAncestor, 
                                                    AncestorType={x:Type ListView}}}"
                                                CommandParameter="{Binding Query}" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>
            </ScrollViewer>


            <Label Grid.Row="5" Target="{Binding ElementName=txtUserQuery}" Content="_Enter your Query:" Foreground="White" />
            <TextBox Name="txtUserQuery" Grid.Row="5" Grid.Column="1" Text="{Binding XPathQuery}"
                     Style="{DynamicResource TextBox_Theme}" Foreground="White" />

            <Button Grid.Row="5" Grid.Column="2" Content="Evaluate" Command="{Binding EvaluateCommand}" Height="24"
                    Style="{DynamicResource Button_Theme}"  
                Background="{StaticResource niceGradient}"/>

            
            <Label Grid.Row="6" Target="{Binding ElementName=txtResults}" Content="_Result:" Foreground="White" />
            <TextBlock Grid.Row="6" Grid.Column="1" Name="txtResults" Text="{Binding XPathResults}" 
                       HorizontalAlignment="Stretch" Foreground="White"
                        />

        </Grid>
    </DockPanel>
</Window>
